package cn.buk.qms.service;

import cn.buk.common.JsonResult;
import cn.buk.common.sc.CommonSearchCriteria;
import cn.buk.tms.dao.CommentDao;
import cn.buk.tms.entity.order.OrderComment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author yfdai
 */
@Component
public class CommentServiceImpl extends BaseAbstractService implements CommentService {

	private final CommentDao commentDao;

	@Autowired
	public CommentServiceImpl(CommentDao commentDao) {
		super();

		this.commentDao = commentDao;
	}

	@Override
	public JsonResult createComment(int enterpriseId, String operator, int orderType, int orderId, String content) {
		OrderComment info = new OrderComment();
		info.setEnterpriseId(enterpriseId);
		info.setOrderType(orderType);
		info.setOrderId(orderId);
		info.setUsername(operator);
		info.setComment(content);

		int retCode = commentDao.create(info);


		return JsonResult.createJsonResult(retCode);
	}

	@Override
	public List<OrderComment> searchComments(int enterpriseId, int orderType, int orderId, CommonSearchCriteria sc) {
		return commentDao.searchComments(enterpriseId, orderType, orderId, sc);
	}
}
